<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" >
      <el-form-item label="任务名称" prop="workName" class="item">
        <el-input
          v-model="queryParams.workName"
          placeholder="请输入任务名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="风险等级" prop="riskGrade" class="item">
        <el-select v-model="queryParams.riskGrade" placeholder="请选择风险等级" clearable size="small">
          <el-option
            v-for="dict in riskGradeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="所属科室" prop="deptName" class="item">
        <treeselect v-model="queryParams.deptId" clearable :options="deptOptions" :disable-branch-nodes="false" :show-count="true" placeholder="请选择归属部门"  style="width:200px;" />
      </el-form-item>
      <el-form-item label="任务来源" prop="workSource" class="item">
        <el-select v-model="queryParams.workSource" placeholder="请选择任务来源" clearable size="small">
          <el-option
            v-for="dict in workSourceOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="输出物名" prop="submitName" class="item">
        <el-input
          v-model="queryParams.submitName"
          placeholder="请输入输出物名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否输出" prop="isSubmitFile" class="item">
        <el-select v-model="queryParams.isSubmitFile" placeholder="请选择是否输出" clearable size="small">
          <el-option
            v-for="dict in isSubmitFileOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="设计失效" prop="isDesignProblem" class="item">
        <el-select v-model="queryParams.isDesignProblem" placeholder="请选择是否设计失效" clearable size="small">
          <el-option
            v-for="dict in isSubmitFileOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
     <el-form-item label="任务时限" class="item">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="是否超时" prop="isTimeOut" class="item">
        <el-select v-model="queryParams.isTimeOut" placeholder="请选择是否超时" clearable size="small">
          <el-option
            v-for="dict in isTimeOutOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="任务状态" prop="state" class="item">
        <el-select v-model="queryParams.state" placeholder="请选择任务状态" clearable size="small">
          <el-option
            v-for="dict in stateOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['work:process:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['work:process:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['work:process:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['work:process:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="processList" @selection-change="handleSelectionChange" border style="width: 100%"
    height="600" :row-class-name="tableRowClassName">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="workId" v-if="false"/>
      <el-table-column label="任务名称" align="center" prop="workName" />
      <el-table-column label="工作内容" align="center" prop="workContent" width="500"/>
      <el-table-column label="风险等级" align="center" prop="riskGrade" width="40" :formatter="riskGradeFormat" />
      <el-table-column label="任务来源" align="center" prop="workSource" :formatter="workSourceFormat" />
      <el-table-column label="所属部门" align="center" prop="deptName" />
      <el-table-column label="设计失效" align="center" prop="isDesignProblem" width="40"  :formatter="isDesignProblemFormat"/>
      <el-table-column label="是否输出" align="center" prop="isSubmitFile" width="40"  :formatter="isSubmitFileFormat" />
      <el-table-column label="输出物名" align="center" prop="submitName" />
      <el-table-column label="开始时间" align="center" prop="startTime" width="100" sortable>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="finishTime" width="100" sortable>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.finishTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否超时" align="center" prop="isTimeOut" width="40" :formatter="isTimeOutFormat" />
      <el-table-column label="任务状态" align="center" prop="state" width="40" :formatter="stateFormat" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['work:process:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-unlock"
            @click="handleResolve(scope.row)"
            v-hasPermi="['work:process:resolve']"
          >分解</el-button>
           <el-button
            size="mini"
            type="text"
            icon="el-icon-download"
            @click="handleImport(scope.row)"
            v-hasPermi="['work:process:file']"
          >附件</el-button>
           <el-button
            size="mini"
            type="text"
            icon="el-icon-tickets"
            @click="handleDetails(scope.row)"
            v-hasPermi="['work:process:details']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['work:process:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改文件任务管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" :close-on-click-modal="false" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="60px">
        <el-form-item label="父级ID" prop="parentId" v-if="false">
          <el-input v-model="form.parentId" placeholder="请输入父级ID" v-if="false"/>
        </el-form-item>

        <el-form-item label="任务名称" prop="workName">
          <el-input v-model="form.workName" placeholder="请输入任务名称" style="width:380px"/>
        </el-form-item>

        <el-form-item label="任务来源" prop="workSource">
          <el-select v-model="form.workSource" clearable placeholder="请选择任务来源" style="width:380px">
            <el-option
              v-for="dict in workSourceOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="所属部门" prop="deptId">
            <treeselect v-model="form.deptId" clearable :options="deptOptions" :disable-branch-nodes="false" :show-count="true" placeholder="请选择归属部门" />
        </el-form-item>

        <el-form-item label="工作内容" prop="workContent">
            <el-input v-model="form.workContent" type="textarea" placeholder="请输入内容" />
        </el-form-item>

        <el-form-item label="风险等级">
          <el-select v-model="form.riskGrade" clearable placeholder="请选择风险等级" style="width:380px">
            <el-option
              v-for="dict in riskGradeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="设计失效">
          <el-radio-group v-model="form.isDesignProblem">
            <el-radio v-for="dict in isDesignProblemOptions" :key="dict.dictValue" :label="dict.dictValue">{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="是否输出">
          <el-radio-group v-model="form.isSubmitFile" @change="isSubmitFileChange">
            <el-radio  v-for="dict in isSubmitFileOptions" :key="dict.dictValue" :label="dict.dictValue">{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="输出物名" prop="submitName">
          <el-input v-model="form.submitName" placeholder="请输入输出物名称" />
        </el-form-item>

        <el-form-item label="任务时限" prop="dateWorkRange">
          <el-date-picker
            v-model="form.dateWorkRange"
            size="small"
            name="se"
            style="width: 380px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>

        <el-form-item label="是否超时" v-if="false">
          <el-select v-model="form.isTimeOut" placeholder="请选择是否超时"  v-if="false">
            <el-option
              v-for="dict in isTimeOutOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="任务状态" v-if="false">
          <el-select v-model="form.state" placeholder="请选择任务状态" style="width:380px">
            <el-option
              v-for="dict in stateOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>

      <!-- 分解模态框 -->
     <el-dialog :title="titleResolve" :visible.sync="openResolve"  :close-on-click-modal="false" width="800px" append-to-body>
      <el-form ref="resolveForm" :model="resolveForm" :rules="resolveRules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="任务ID" prop="workId" v-if="false">
              <el-input v-model="resolveForm.workId" placeholder="请输入任务ID" v-if="false"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="userIds" label="人员姓名">
              <el-select v-model="resolveForm.userIds" clearable multiple  style="width:100%" @change="selectUserChange">
                <el-option v-for="item in usersOptions" :key="item.userId" :label="item.nickName" :value="item.userId" :disabled="item.states == 1" ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属组别" prop="groups">
              <el-select v-model="resolveForm.groups" multiple  filterable  placeholder="请选择" prop="groupType" style="width:100%">
                <el-option v-for="item in groupTypeOptions" :key="item.id" :label="item.name" :value="item.code" :disabled="item.states == 1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="fileId" label="文件时长">
              <el-select v-model="resolveForm.fileId" clearable  style="width:100%">
                <el-option v-for="item in filesOptions" :key="item.fileId" :label="item.name" :value="item.fileId" :disabled="item.state == 1" ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="录入次数" prop="number">
              <el-input v-model="resolveForm.number" type="number" oninput="if(value>60)value=60" onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode)))' placeholder="请输入录入次数" maxlength="2" style="width:100%"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="任务时限" prop="dateRange">
              <el-date-picker
                v-model="resolveForm.dateRange"
                size="small"
                name="se"
                style="width: 100%"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @change="selectUserChange"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24"  v-if="resolve.isPeopleWorkLineShow" >
                <AnalyzeEasyLineCharts class="middleTwo" :handleOfficeLineCharts="handlePeopleLineCharts" :chart-data="peopleCompositeLineCharts" />
          </el-col>
        </el-row>
      </el-form>
       <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitResolveForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

     <!-- 上传文件 -->
     <el-dialog :title="titleUpload" :visible.sync="openUpload" :close-on-click-modal="false"  width="800px" append-to-body>
      <el-tabs v-model="activeName">
        <el-tab-pane id="processUpload" label="上传" name="first">
              <el-upload ref="upload"
              :headers="headers"
              :limit="1"
              :data="uploadData"
              :action="url"
              :disabled="isUploading"
              :on-progress="handleFileUploadProgress"
              :on-success="handleFileSuccess"
              :auto-upload="false" drag>
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">
                将文件拖到此处，或
                <em>点击上传</em>
              </div>
            <!-- <div class="el-upload__tip" slot="tip" style="color:red;textAlign:center">提示：仅允许导入“doc”或“docx”,“xls”或“xlsx”格式文件！</div> -->
            </el-upload>
          <el-button type="primary" @click="submitFileForm" style="display:block;margin:0 auto;marginTop:1em">上 传</el-button>
        </el-tab-pane>
        <el-tab-pane label="附件查看" name="second">
            <el-row :gutter="10" class="mb8">
            </el-row>
            <el-table v-loading="loading" :data="fileLists" border @selection-change="handleSelectionFileChange" >
                  <el-table-column type="selection" width="55" align="center" />
                  <el-table-column label="文件ID" align="center" prop="id" v-if="false"/>
                  <el-table-column label="文件URL" align="center" prop="url" v-if="false"/>
                  <el-table-column label="文件名称" align="center" prop="name"/>
                  <el-table-column label="文件类型" align="center" prop="type" :formatter="stateFileTypeFormat" />
                  <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                      <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-edit"
                        @click="handleFileDownload(scope.row)"
                      >下载</el-button>
                      <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-delete"
                        @click="handleFileDelete(scope.row)"
                        v-hasPermi="['work:process:fileremove']"
                      >删除</el-button>
                    </template>
                  </el-table-column>
            </el-table>
        </el-tab-pane>
      </el-tabs>
      <!--
       -->
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitFileForm">确 定</el-button> -->
        <el-button @click="openUpload = false">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listProcess, getProcess, delProcess, addProcess, updateProcess, exportProcess,getUsers,listHours,selectFiles,groupList } from "@/api/work/process";
import { addProcessAndResolve,deleteFiles,downloadFile} from "@/api/work/user";
import { treeselect } from "@/api/system/dept";
import { getToken } from '@/utils/auth';
import { download } from '@/utils/ruoyi';
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import AnalyzeEasyLineCharts from '../../statistics/linecharts/AnalyzeEasyLineChart';
import { queryPeopleCompositeTotalLineCharts } from "@/api/statistics/work/composite";
import echarts from 'echarts';
export default {
  name: "Process",
  components: {
    Treeselect,
    AnalyzeEasyLineCharts
  },
  data() {
    return {
      // 日期范围
      dateRange: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 文件任务管理表格数据
      processList: [],
      // 弹出层标题
      title: "",
      //分解层标题
      titleResolve: "",
      // 是否显示弹出层
      open: false,
      // 上传标签页
      activeName: 'first',
      //组别
      groupTypeOptions: [],
      // 弹出层标题
      title: "",
      titleComplete: "",
      titleUpload: "",
      fileLists: [{
        id:'',
        url: "",
        name: '',
        type: ''
      }],
      // 设置上传的请求头部
      headers: { Authorization: 'Bearer ' + getToken()},
      // 是否禁用上传
      isUploading: false,
      openResolve:false,
      // 是否显示弹出层
      open: false,
      openComplete: false,
      openUpload: false,
      //文件类型字典
      textFileTypeOptions: [],
      // 风险等级字典
      riskGradeOptions: [],
      // 任务来源字典
      workSourceOptions: [],
      // 是否提交见证性材料字典
      isSubmitFileOptions: [],
      //是否属于设计问题
      isDesignProblemOptions:[],
      // 是否超时字典
      isTimeOutOptions: [],
      //文本工时
      textHoursOptions:[],
      // 任务状态字典
      stateOptions: [],
      // 人员选项
      usersOptions: [],
      // 部门树选项
      deptOptions: [],
      //默认树列表字段
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      // 文件时长选项
      filesOptions:[],
      //任务ID
      workId:null,
       //人员近30天工作
      peopleCompositeLineCharts:{},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workName: null,
        riskGrade: null,
        workSource: null,
        submitName: null,
        isSubmitFile: null,
        isTimeOut: null,
        state: null,
        deptId: null,
      },
      uploadData: {
        tableId: null
      },
      workId:null,
      // 上传的地址
      url: process.env.VUE_APP_BASE_API+"/work/process/upload",
      //路径
      baseURL:  process.env.VUE_APP_BASE_API,
      // 表单参数
      form: {
        //工时范围
        dateWorkRange: ''
      },
      resolveForm:{
        //工时范围
        dateRange:[],
      },
      //分解人员工作参数
      resolve :{
         //是否显示人员统计
          isPeopleWorkLineShow: false,
          //查询统计图参数
          queryTotal:{
              userId: null,
              beginTime: null,
              endTime: null
          }
      },
      // 表单校验
      rules: {
        workName: [
          { required: true, message: "任务名称不能为空", trigger: "blur" }
        ],
        workContent: [
          { required: true, message: "工作内容不能为空", trigger: "blur" }
        ],
        isSubmitFile: [
          { required: true, message: "是否输出不能为空", trigger: "blur" }
        ],
        submitName: [
          { required: true, message: "输出物名不能为空", trigger: "blur" }
        ],
        workSource: [
          { required: true, message: "任务来源不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "所属部门不能为空", trigger: "blur" }
        ],
        dateWorkRange: [
          {
            type: 'array',
            required: true,
            message: '请选择日期区间',
            fields: {
              //tpye类型试情况而定,所以如果返回的是date就改成date
              0: { type: 'string', required: true, message: '请选择开始日期' },
              1: { type: 'string', required: true, message: '请选择结束日期' }
            }
          }
        ]
      },
      // 分解表单校验
      resolveRules: {
        userIds: [
          { required: true, message: "用户名不能为空", trigger: "blur" }
        ],
        fileId: [
          { required: true, message: "每日工作时长不能为空", trigger: "blur" }
        ],
        groups:[
          { required: true, message: "所属组别不能为空", trigger: "blur" }
        ],
        dateRange: [
          {
            type: 'array',
            required: true,
            message: '请选择日期区间',
            fields: {
              //tpye类型试情况而定,所以如果返回的是date就改成date
              0: { type: 'string', required: true, message: '请选择开始日期' },
              1: { type: 'string', required: true, message: '请选择结束日期' }
            }
          }
        ]
      },
      layerOptions :{
        type: 0, //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
        title: '信息',
        content: '',
        area: 'auto',
        offset: 'auto',
        icon: -1,
        btn: '确定',
        time: 0,
        shade: true,//是否显示遮罩
        yes: '',
        cancel: '',
        tips: [0,'#c00'],//支持上右下左四个方向，通过1-4进行方向设定,可以设定tips: [1, '#c00']
        tipsMore: false,//是否允许多个tips
        shadeClose: true,//点击遮罩是否关闭
      },
    };
  },
  mounted(){

  },
  created() {
    this.getList();
    this.getTreeselect();
    this.handleGroupList();
    this.getDicts("work_risk_grade").then(response => {
      this.riskGradeOptions = response.data;
    });
    this.getDicts("work_file_source").then(response => {
      this.workSourceOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.isSubmitFileOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.isDesignProblemOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.isTimeOutOptions = response.data;
    });
    this.getDicts("work_file_state").then(response => {
      this.stateOptions = response.data;
    });
    this.getDicts("work_text_hours").then(response => {
      this.textHoursOptions = response.data;
    });
    this.getDicts("sys_file_type").then(response => {
      this.textFileTypeOptions = response.data;
    });
  },

  methods: {
    /** 查询文件任务管理列表 */
    getList() {
      this.loading = true;
      listProcess(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
        this.processList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //修改列颜色
    tableRowClassName({row, rowIndex}) {
        if (row.isTimeOut === 'Y') {
          return 'danger-row';
        }
    },
    // 风险等级字典翻译
    riskGradeFormat(row, column) {
      return this.selectDictLabel(this.riskGradeOptions, row.riskGrade);
    },
    // 任务来源字典翻译
    workSourceFormat(row, column) {
      return this.selectDictLabel(this.workSourceOptions, row.workSource);
    },
    // 是否提交见证性材料字典翻译
    isSubmitFileFormat(row, column) {
      return this.selectDictLabel(this.isSubmitFileOptions, row.isSubmitFile);
    },
    // 是否属于设计问题字典翻译
    isDesignProblemFormat(row, column) {
      return this.selectDictLabel(this.isDesignProblemOptions, row.isDesignProblem);
    },
    // 是否超时字典翻译
    isTimeOutFormat(row, column) {
      return this.selectDictLabel(this.isTimeOutOptions, row.isTimeOut);
    },
    // 任务状态字典翻译
    stateFormat(row, column) {
      return this.selectDictLabel(this.stateOptions, row.state);
    },
    // 文件类型翻译
    stateFileTypeFormat(row, column) {
      return this.selectDictLabel(this.textFileTypeOptions, row.type);
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openResolve = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        workId: null,
        parentId: null,
        deptId: null,
        workName: null,
        workContent: null,
        riskGrade: null,
        workSource: null,
        workGroup: null,
        submitName: null,
        isSubmitFile: "Y",
        isDesignProblem: "N",
        startTime: null,
        finishTime: null,
        isTimeOut: null,
        state: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        dateRange: null,
        dateWorkRange: null
      };
      this.resetForm("form");

      this.resolveForm = {
        dateRange:[],
        itemId: null,
        workId: null,
        userIds: null,
        workHours: null,
        fileHours: null,
        fileId: null,
        textHours: null,
        startTime: null,
        finishTime: null,
        number:1
      }
       this.resetForm("resolveForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.workId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getTreeselect();
      this.open = true;
      this.title = "添加日常任务";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getTreeselect();
      const workId = row.workId || this.ids
      getProcess(workId).then(response => {
        this.form = response.data;
        this.$set(this.form,"dateWorkRange",[response.data.startTime, response.data.finishTime]);
        this.open = true;
        this.title = "修改日常任务";
      });
    },
     /** 查询未录入用户下拉 */
    getUsersList(deptId) {
      getUsers(deptId).then((response) => {
        this.usersOptions = response.data;
        // console.log("返回数据"+JSON.stringify(response.data));
      });
    },
    getFilesList(deptId){
      listHours(deptId).then((response) => {
        this.filesOptions = response.data;
      });
    },
    // 分解操作
    handleResolve(row){
      this.workId = row.workId;
      this.getUsersList(row.deptId);
      this.getFilesList(row.deptId);
      this.reset();
      this.resolveForm.dateRange = [row.startTime,row.finishTime];
      this.openResolve = true;
      this.resolve.isPeopleWorkLineShow = false;
      this.peopleCompositeLineCharts = {};
      this.titleResolve = "分解任务";
    },
    // 提交分解表单
    submitResolveForm(){
      this.$refs["resolveForm"].validate(valid => {
        this.resolveForm.workId = this.workId;
        this.resolveForm.workType = 0;
        if (valid) {
            addProcessAndResolve(this.addFinishDateRange(this.resolveForm, this.resolveForm.dateRange)).then(response => {
              if (response.code === 200) {
                this.msgSuccess("分解成功");
                this.openResolve = false;
              }
            });
            this.dateRange=[];
            this.getList();
          }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.workId != null) {
            updateProcess(this.addFinishDateRange(this.form, this.form.dateWorkRange)).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addProcess(this.addFinishDateRange(this.form, this.form.dateWorkRange)).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
          this.dateRange = [];
          this.getList();
        }
        this.getList();
      });
    },
    // 添加日期范围
    addFinishDateRange(params, dateRange) {
      var search = params;
      search.startTime = "";
      search.finishTime = "";
      if (null != dateRange && '' != dateRange) {
        search.startTime = dateRange[0];
        search.finishTime = dateRange[1];
      }
      return search;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const workIds = row.workId || this.ids;
      this.$confirm('是否确认删除文件任务编号为"' + workIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delProcess(workIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有文件任务数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportProcess(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },
    /** 详情按钮操作 */
    handleDetails(row) {
      if(null!=row.workId&&row.workId!=''&row.workId!=undefined){
          this.$router.push({
            path:'/work/processuser',
            query:{
              workId:row.workId,
              deptId:row.deptId,
              startTime: row.startTime,
              finishTime: row.finishTime,
              data:row
            }
          })
      }else{
         this.msgError("浏览器错误，请刷新后重试");
      }

    },
    /** 查询附件列表 */
    getFileList() {
      this.loading = true;
      selectFiles(this.workId).then((response) => {
        this.fileLists = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 上传按钮操作 */
    handleImport(row) {
      const workId = row.workId || this.ids;
      this.titleUpload = "上传与附件";
      this.openUpload = true;
      this.uploadData.tableId = workId;
      this.workId = workId;
      this.getFileList();
    },
    // 下载文件
    handleFileDownload(row){
      const id = row.id || this.id;
      const url = row.uri || this.uri;
      window.location.href = this.baseURL+url;
    },
    // 删除文件操作
    handleFileDelete(row){
      const id = row.id || this.id;
      this.$confirm('是否确认删除任务分配编号为"' + id + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return deleteFiles(id);
        }).then(() => {
          this.getFileList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.openUpload = true;
      this.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "上传结果", { dangerouslyUseHTMLString: true });
      this.getList();
      this.getFileList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },

    handleSelectionFileChange(selection){
      this.id = selection.map(item => item.id)
      this.uri = selection.map(item => item.uri)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleGroupList(){
      groupList().then((response) => {
        this.groupTypeOptions = response.data;
      });
    },
    //是否输出必填项校验
    isSubmitFileChange(value){
      if('Y'==value){
          this.rules.submitName[0].required = true;
      }else{
          this.rules.submitName[0].required = false;
      }
    },
    // 查询人员最近30天工作曲线
    handlePeopleLineCharts(params){
        let userName = "";
        queryPeopleCompositeTotalLineCharts(params).then(response => {
            let newObject = {
                xdata:[],
                ydata:[],
                zdata:[],
                adata:[],
                bdata:[]
            }
            response.forEach((item,index)=>{
                newObject.xdata.push(item.time)
                newObject.ydata.push(item.totalValue)
                userName = item.name;
            })
            newObject.bdata.push(userName+":近30天工作量曲线（H）");
            this.peopleCompositeLineCharts = newObject
        });
    },
    //查询人员工作曲线图
    queryPeopleWorkLine(){
      if(null==this.resolveForm.userIds||""==this.resolveForm.userIds){
            this.$message({
              showClose: true,
              message: '请选人人员信息',
              type: 'warning'
            });
            return;
      }
      if(null==this.resolveForm.dateRange){
            this.$message({
              showClose: true,
              message: '请选择任务时限',
              type: 'warning'
            });
            return;
      }
      let userIds = this.resolveForm.userIds;
      let userId  = userIds[userIds.length-1];
      this.resolve.queryTotal.userId = userId;
      this.resolve.queryTotal.beginTime = this.resolveForm.dateRange[0];
      this.resolve.queryTotal.endTime = this.resolveForm.dateRange[1];
      this.handlePeopleLineCharts(this.resolve.queryTotal);
      this.resolve.isPeopleWorkLineShow = true;
    },
    //监听选择用户事件
    selectUserChange(value){
      this.queryPeopleWorkLine();
    },
  }
};
</script>
<style>
.el-upload-list__item-name{
    font-size: 16px;
}
#processUpload .el-upload-dragger{
  display:block;
  margin:0 auto;
  margin-top:1em;
  width: 760px;
  height: 180px;
}
.el-table .warning-row {
  background: rgb(248, 226, 186);
}

.el-table .success-row {
  background: #ffffff;
}

.el-table .danger-row {
  background: #f8b690;
}
</style>
